using System.Web.Mvc;
using Evolus.Mercury.Web.Models;
using System.Collections.Generic;
using Evolus.Mercury.Model;
using System;

namespace Evolus.Mercury.Web.Controllers
{
    public class MobileController : Controller
    {
        IMarketService marketInfoService;

        public MobileController(IMarketService marketInfoService)
        {
            this.marketInfoService = marketInfoService;
        }

        //
        // GET: /Mobile/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult MarketInfo()
        {
            StockQuote[] changedItems = new StockQuote[] 
            {
                new StockQuote("ACB", 14.2m, 4.5m, ChangeType.Up),
                new StockQuote("VCB", 14.2m, 4.5m, ChangeType.Down),
                new StockQuote("PIT", 14.2m, 4.5m, ChangeType.Ceiling),
                new StockQuote("BBT", 14.2m, 4.5m, ChangeType.Floor),
                new StockQuote("BTC", 14.2m, 4.5m, ChangeType.Freeze),
            };            

            return Json(changedItems, "text/plain");
        }

        public JsonResult GetQuotes(string[] symbols, DateTime lastUpdatedTime)
        {            
            IList<StockInfo> stockInfos = marketInfoService.GetChanges(symbols, lastUpdatedTime);
            IList<StockQuote> changedItems = new List<StockQuote>();
            foreach (StockInfo stockInfo in stockInfos)
            {
                changedItems.Add(new StockQuote(stockInfo));
            }
            return Json(changedItems, "text/plain");
        }
    }
}
